<?php

namespace web\common\command;

use addons\member\model\MemberAccountModel;
use web\common\model\sys\SysParameterModel;
use think\Config;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\input\Argument;
use think\console\Output;
use think\Exception;
use think\Db;
use web\common\service\Credential;

class Crontab extends Command{

    /**
     * 定义命令
     */
    protected function configure(){
        $this->setName('Crontab')->setDescription('RUN ETH Data RPC API');
        $this->addArgument('action', Argument::REQUIRED, "The name of the function");
        //参数2
        $this->addArgument('param', Argument::OPTIONAL, "The name of the param");
    }
    
    protected function execute(Input $input, Output $output) {
        $action = $input->getArgument('action');
        $param = $input->getArgument('param');
        if (method_exists($this,$action)) {
            $this->$action($param);
        }
        else{
            echo "method is not exists\n";
        }
    }

    /**
     * 实时更新等级
     */
    public function updateLevel(){
        $accountM = new \addons\member\model\MemberAccountModel();
        $user_list = $accountM->where(['level' => ['>', 0], 'is_frozen' => 0, 'is_auth' => 1, 'logic_delete' => 0])->order('id desc')->select();
        $hashrateM = new \addons\member\model\MemberHashrate();
        $equipOrderM = new \addons\equip\model\EquipOrder();
        if($user_list){
            //算出用户自身算力
            $hashrateM->where(' 1=1 ')->delete();
            foreach ($user_list as $value){
                echo $value['id'];echo '--';
                //算出自身的算力
                $tota_hashrate_amount = $equipOrderM->where(['user_id' => $value['id'], 'status' => 0, 'hashrate_amount' => ['>', 0]])->sum('hashrate_amount')??0;
                if($tota_hashrate_amount > 0){
                    $hashrateM->updateOneselfHashrate($value['id'], $tota_hashrate_amount);
                }
            }
        }
        echo "=====";

        $hashrate_list = $hashrateM->where(' 1 = 1 ')->order('user_id asc')->select();
        if($hashrate_list){
            //算出没用用户的小区算力
            foreach($hashrate_list as $value){
                echo $value['user_id'];echo '--';
                $communityHashrate = $hashrateM->getCommunityHashrate($value['user_id']);
                $hashrateM->where(['user_id' => $value['user_id']])->update(['community_hashrate' => $communityHashrate, 'update_time' => date("Y-m-d H:i:s")]);
            }
        }
        echo "=====";

        if($user_list){

            $levelConfigM = new \addons\member\model\LevelConfig();
            //升级用户
            foreach ($user_list as $value){
                $level = 1;
                $order_count = $equipOrderM->where(['user_id' => $value['id'], 'e_id' => ['>', 1]])->count();
                $level_count = $accountM->where(['pid' => $value['id'], 'level' => ['>', 0], 'is_frozen' => 0, 'is_auth' => 1, 'logic_delete' => 0])->count();

                if($order_count > 0 || $level_count >=3){
                    $level = 2;

                    $did_count = $accountM->where(['pid' => $value['id'], 'level' => ['>', 0], 'is_frozen' => 0, 'is_auth' => 1, 'logic_delete' => 0])->count();
                    $hashrate_data = $hashrateM->where(['user_id' => $value['id']])->find();

                    if($hashrate_data){

                        $where = [
                            'level' => ['>', 2],
                            'effective_direct_number' => ['<=', $did_count],
                            'managed_to_force' => ['<=', $hashrate_data['team_oneself_hashrate']],
                            'community_to_force' => ['<=', $hashrate_data['community_hashrate']],
                        ];
                        $level_data = $levelConfigM->where($where)->order('level desc')->find();
                        if($level_data){
                            $level = $level_data['level'];
                        }
                    }

                }
                if($value['level'] != $level){
                    echo $value['id'];echo '--';
                    if($value['admin_level'] > 0){
                        $level = $value['admin_level'];
                    }
                   $accountM->where(['id' => $value['id']])->update(['level' => $level, 'update_time' => NOW_DATETIME]);
                }
            }
        }
        return 'ok';
    }

    /**
     * 锁仓释放
     */
    public function lockUpRelease(){
        $lockUpM = new \addons\equip\model\LockUp();
        $lock_list = $lockUpM->where(['status' => 0, 'release_tax' => ['>', 0]])->select();
        if($lock_list){
//            $balanceM = new \addons\member\model\Balance();
//            $recordM = new \addons\member\model\TradingRecord();
            $forLogM = new \addons\member\model\RewardForLog();
            $sysParameterM = new \web\common\model\sys\SysParameterModel();
            $dc_price = $sysParameterM->getValByName('dc_price');
            $kof_price = $sysParameterM->getValByName('kof_price');
            foreach ($lock_list as $value){
                echo $value['id'];echo '--';

                $release_amount = round(($value['amount'] * $value['release_tax'] / 100), 4);
                if($value['remaining_amount'] < $release_amount){
                    $release_amount = $value['remaining_amount'];
                }
                //普通锁仓
                if($value['type'] != 1){
                    //dc释放对等KOF数量
                    $kof_balance_type = 3;
                    if($value['type'] == 2){    //代理锁仓
                        $kof_amount = round(($release_amount * $dc_price / $kof_price), 4);
                        $re = $forLogM->addRecord($value['user_id'], 0, $kof_balance_type, 103, $kof_amount, '锁仓释放');
                    }
                    if($value['type'] == 3){    //希望锁仓
                        if($value['balance_type'] == 2){
                            $kof_amount = round(($release_amount * $dc_price / $kof_price), 4);
                            $re = $forLogM->addRecord($value['user_id'], 0, $kof_balance_type, 103, $kof_amount, '锁仓释放');
                        }
                        if($value['balance_type'] == 3){
                            $re = $forLogM->addRecord($value['user_id'], 0, $value['balance_type'], 103, $release_amount, '锁仓释放');
                        }
                    }

                }else{
                    $re = $forLogM->addRecord($value['user_id'], 0, $value['balance_type'], 103, $release_amount, '锁仓释放');
                }
                $update_data = [
                    'remaining_amount' => ($value['remaining_amount'] - $release_amount),
                    'update_time' => date("Y-m-d H:i:s"),
                ];
                if(($value['remaining_amount'] - $release_amount) <= 0){
                    $update_data['status'] = 1;
                }
                $lockUpM->where(['id' => $value['id']])->update($update_data);
            }
        }
        echo 'ok';
    }

    /**
     * 动态奖励过期
     */
    public function dynamicOverdue(){
        (new \addons\member\model\RewardForLog())->where(['create_time' => ['<', date("Y-m-d 00:00:00", time() - 90000)], 'is_receive' => 0, 'type' => ['<>', 103]])->update(['is_receive' => 2, 'update_time' => NOW_DATETIME]);
        echo 'ok';
    }

    /**
     * 锁仓奖励过期
     */
    public function lockUpOverdue(){
        (new \addons\member\model\RewardForLog())->where(['create_time' => ['<', date("Y-m-d 00:00:00", time() - 20000)], 'is_receive' => 0, 'type' => 103])->update(['is_receive' => 2, 'update_time' => NOW_DATETIME]);
        echo 'ok';
    }

    /**
     * 结束矿机
     */
    public function endEquip(){
        $equipOrderM = new \addons\equip\model\EquipOrder();
        $equipOrderM->where(['status' => 0, 'end_time' => ['<', date('Y-m-d H:i:s')]])->update(['status' => 1, 'update_time']);
        echo 'ok';
    }

    /**
     * 极差释放
     */
    public function teamRevenueAward(){
        $logicC = new \web\common\utils\MealLogic();
        $teamRevenueAwardM = new \addons\equip\model\TeamRevenueAward();
        $accountM = new \addons\member\model\MemberAccountModel();
        $list = $teamRevenueAwardM->where(['is_issue' => 0])->select();
        if($list){
            foreach ($list as $value){
                echo $value['id'];echo '--';

                $pid_path = $accountM->where(['id' => $value['user_id']])->value('pid_path');

                $pid_drr = [];
                if($pid_path != ',,'){
                    $pid_drr = explode(',',$pid_path);
                }
                $max_level = $accountM->where(['id' => ['in', $pid_drr]])->order('level desc')->value('level');

                $logicC->leadershipAward($value['pid'], $value['user_id'], $value['release_balance_type'], $value['amount'], $max_level, $value['remark']);
                $teamRevenueAwardM->where(['id' => $value['id']])->update(['is_issue' => 1, 'update_time' => date("Y-m-d H:i:s")]);
            }
        }
        echo 'ok';
    }

    /*********************************/

    public function test(){

//        $credential = Credential::create();
//        $address = (string)$credential->address();
//        $trc['privatekey'] = $credential->privateKey();
//        $trc['pass'] = $credential->publicKey();
//        $trc['address'] = $address;
//        dump($trc);die;

//        $aaaaM = new \addons\member\model\MemberAccountAAAAModel();
//        $accountM = new \addons\member\model\MemberAccountModel();
//        $user_list = $aaaaM->where(['pid_path' => ["like", "%,767,%"]])->select();
//
//        foreach ($user_list as $value){
//            echo $value['id'];echo '--';
//            $accountM->where(['id' => $value['id']])->update($value);
//        }
//
//        echo 'ok';
//        $data = (new \addons\member\model\MemberAccountModel())->getDetail(193, 'id,eth_address');
//        (new \web\common\utils\Coin())->getUsdtOrders(193, $data['eth_address'],1);

//        $eth_address_data = (new \web\common\utils\Coin())->createEthAddress();
//        dump($eth_address_data);die;
//        $recordM = new \addons\member\model\TradingRecord();
//        $list = $recordM->where(['update_time' => ['>', '2020-12-28 12:42:40'], 'user_id' => 12, 'id' => ['<', 1694352]])->select();
////        dump($list);die;
//
//        $balanceM = new \addons\member\model\Balance();
//        foreach ($list as $value){
//            echo $value['id'];echo '--';
//            $re_balance = $balanceM->updateBalance($value['user_id'], $value['asset_type'], $value['amount'], false);
//            $recordM->where(['id' => $value['id']])->delete();
//        }
//echo 'ok';
    }

    /**
     * 更新等级
     */
    public function daysLevelUp(){
        $rewardM = new \addons\member\utils\Reward;
        $rewardM->allLevelup();
    }
    
    /**
     * 奖励发放
     */
    public function bonusRelease(){
        $m = new \addons\member\model\DailyBonus;
        // $data = $m->where(['create_time'=>date('Y-m-d',strtotime('-1 days')),'is_issue'=>0])->find();
        $data = $m->where(['create_time'=>date('Y-m-d'),'is_issue'=>0])->find();
        if(!$data){
            echo "done \n";exit();
        }
        if($data['amount']==0){
            echo "done \n";exit();
        }
        $orderM = new \addons\member\model\DailyBonusRecord;
        $memberM = new MemberAccountModel;
        $BalanceM = new \addons\member\model\Balance();
        $recordM = new \addons\member\model\TradingRecord();
        $BalanceM->startTrans();
        $res = $m->where('id',$data['id'])->update(['is_issue'=>1,'update_time'=>NOW_DATETIME]);
        if(!$res){
            $BalanceM->rollback();
            echo "save fail \n";exit();
        }
        for ($i=1; $i <=4 ; $i++) { 
            $$i = $memberM->where(['level'=>$i])->field('id')->select();
            echo "i:{$i}---".count($$i)."||";
            if($$i){
                $level_data = (new \addons\member\model\LevelConfig)->column('level,rate');
                $release_amount = bcmul($data['amount']/count($$i), $level_data[$i]/100,4);
                echo "|release_amount:{$release_amount}|";
                foreach ($$i as $key => $v) {
                    $BalanceM->startTrans();
                    $res = $orderM->addRecord($v['id'],$data['id'],$release_amount,1,'14',1,'手续费分红'.$i);
                    if(!$res){
                        $BalanceM->rollback();
                        continue;
                    }
                    $res = $this->addAmount($v['id'],$release_amount,14,1,'手续费分红'.$i,$BalanceM,$recordM);
                    if(!$res){
                        $BalanceM->rollback();
                        continue;
                    }
                    $BalanceM->commit();
                }
            }
        }
        $BalanceM->commit();
        echo "release done \n";
    }

    /**
     * 发放静态
     */
    public function staticRelease(){
        $orderM = new \addons\equip\model\UnitedCreateOrder;
        $page = 0;
        $index = 0;
        $page_index = $page*$index;
        $rows = 100;
        $today = date('Y-m-d');
        $map['update_time'] = ['<',$today];
        $map['start_time'] = ['<',$today];
        $field = '*';
        $list = $orderM->field($field)->where($map)->limit($page_index,$rows)->select();
        $memberM = new MemberAccountModel;
        $BalanceM = new \addons\member\model\Balance();
        $recordM = new \addons\member\model\TradingRecord();
        $rewardM = new \addons\member\utils\Reward;        
        while ($list) {
            foreach ($list as $k => $v) {
                $release_amount = bcmul($v['o_amount'], $v['days_release']/100,4);
                $data = [
                    'total_release'=>$v['total_release']+$release_amount,
                    'today_release'=>$release_amount,
                    'update_time'=>NOW_DATETIME,
                ];
                $BalanceM->startTrans();
                $res = $orderM->where('id',$v['id'])->update($data);
                if(!$res){
                    $BalanceM->rollback();
                    continue;
                }
                $res = $this->addAmount($v['user_id'],$release_amount,10,1,$v['equip_name'],$BalanceM,$recordM);
                if(!$res){
                    $BalanceM->rollback();
                    continue;
                }
                $BalanceM->commit();
                //发放动态奖励
            }
            // $page++;
            $index++;
            echo "page:{$page}|index:{$index} \n";
            $list = $orderM->field($field)->where($map)->limit($page_index,$rows)->select(); 
        }
        echo "done \n";
    }


    /**
     * 指导票扣除
     */
    public function guideDec(){
        return false;
        $BalanceM = new \addons\member\model\Balance();
        $page = 0;
        $rows = 100;
        // $rows = 100;
        $page_index = $page*$rows;
        $index = 0;
        $field = '*';        
        $map['type'] = 3;
        $map['amount'] = ['>',0];
        $list = $BalanceM->field($field)->where($map)->limit($page_index,$rows)->select();
        $recordM = new \addons\member\model\TradingRecord();
        while ($list) {
            foreach ($list as $k => $v) {
                if($v['amount']==0) continue;
                $release_amount = $v['amount'];
                $BalanceM->startTrans();
                $res = $this->addAmount($v['user_id'],$release_amount,14,3,'系统回收',$BalanceM,$recordM,0,0);
                if(!$res){
                    $BalanceM->rollback();
                    continue;
                }
                $BalanceM->commit();
                //发放动态奖励
            }
            // $page++;
            $index++;
            echo "page:{$page}|index:{$index} \n";
            $list = $BalanceM->field($field)->where($map)->limit($page_index,$rows)->select(); 
        }
        echo "done \n";
    }


    /**
     * 指导票退回
     */
    public function guideReturn(){
        $recordM = new \addons\member\model\TradingRecord();
        $BalanceM = new \addons\member\model\Balance();
        $page = 0;
        $rows = 100;
        // $rows = 100;
        $index = 0;
        $field = 'user_id,amount';        
        $map['type'] = 14;
        $map['change_type'] = 0;
        $list = $recordM->field($field)->where($map)->limit($page*$rows,$rows)->select();
        while ($list) {
            foreach ($list as $k => $v) {
                if($v['amount']==0) continue;
                $release_amount = $v['amount'];
                $recordM->startTrans();
                $res = $this->addAmount($v['user_id'],$release_amount,14,3,'系统回收',$BalanceM,$recordM,0,1);
                if(!$res){
                    $recordM->rollback();
                    continue;
                }
                $recordM->commit();
                //发放动态奖励
            }
            $page++;
            // $index++;
            echo "page:{$page}|index:{$index} \n";
            $list = $recordM->field($field)->where($map)->limit($page*$rows,$rows)->select(); 
        }
        echo "done \n";
    }

    private function addAmount($user_id,$amount,$type,$coin_type,$remark,$BalanceM,$recordM,$to_user_id=0,$change_type=1){
        $re_balance = $BalanceM->updateBalance($user_id, $coin_type, $amount,$change_type);
        if(!$re_balance){
            return false;
        }
        $userRecord = $recordM->addRecord($user_id, $amount, $re_balance['before_amount'], $re_balance['amount'], $coin_type, $type, $change_type, $to_user_id, $remark);
        if(!$userRecord){
            return false;
        }
        return true;
    }


    /**
     * 定时器释放最新的交易矿池记录
     */
    public function CrontabRelease(){
        $CrontabM = new \addons\config\model\Crontab;
        $map = [];
        $map['status'] = 0;
        $field = '*';
        $page = 0;
        $rows = 100;
        $list = $CrontabM->where($map)->field($field)->limit($page*$rows,$rows)->select();
        $rewardM = new \addons\member\utils\Reward;
        while ($list) {
            foreach ($list as $k => $v) {
                $name = $v['method'];
                $this->$name($v,$CrontabM,$rewardM);
            }
            // $page++;
            echo "page:{$page} \n";
            $list = $CrontabM->where($map)->field($field)->limit($page*$rows,$rows)->select();
        }
        echo "done \n";
    }

    private function addTicket($data,$CrontabM,$rewardM){
        echo "addTicket {$data['id']} \n";
        $status = $CrontabM->where('id',$data['id'])->value('status');
        if($status==1) return true;
        $update_data['status'] = 1;
        $update_data['update_time'] = NOW_DATETIME;
        $res = $CrontabM->where('id',$data['id'])->update($update_data);
        $amount = $data['amount'];
        $level = $data['rate'];
        $memberM = new MemberAccountModel;
        $BalanceM = new \addons\member\model\Balance();
        $recordM = new \addons\member\model\TradingRecord();
        $page = 0;
        $index = 0;
        $rows = 100;
        $field = 'id';
        $map['level'] = $level;
        $list = $memberM->field($field)->where($map)->limit($page*$rows,$rows)->select(); 
        while ($list) {
            foreach ($list as $k => $v) {
                $BalanceM->startTrans();
                $res = $this->addAmount($v['id'],$amount,20,1,'星级奖励',$BalanceM,$recordM);
                if(!$res){
                    $BalanceM->rollback();
                    continue;
                }
                $BalanceM->commit();
                //发放动态奖励
            }
            $page++;
            // $index++;
            echo "page:{$page}|index:{$index} \n";
            $list = $memberM->field($field)->where($map)->limit($page*$rows,$rows)->select(); 
        }
        echo "done \n";
    }

    /**
     * 关系变换
     */
    private function relation($data,$CrontabM,$rewardM){
        echo "relation {$data['id']} \n";
        $status = $CrontabM->where('id',$data['id'])->value('status');
        if($status==1) return true;
        $update_data['status'] = 1;
        $update_data['update_time'] = NOW_DATETIME;
        $res = $CrontabM->where('id',$data['id'])->update($update_data);
        $fixM = new \web\common\command\Fix;
        $fixM->fixParent();
        $fixM->fixNumber();
        $fixM->fixCom();
        $fixM->fixActivity();
        echo "fixDone\n";
    }
    /**
     * 购买equip
     */
    private function rewardRelease($data,$CrontabM,$rewardM){
        echo "rewardRelease {$data['id']} \n";
        $status = $CrontabM->where('id',$data['id'])->value('status');
        if($status==1) return true;
        $update_data['status'] = 1;
        $update_data['update_time'] = NOW_DATETIME;
        // $CrontabM->startTrans();
        $res = $CrontabM->where('id',$data['id'])->update($update_data);
        //计算用户等级
        $rewardM->userUpdate($data['user_id']);
        $rewardM->VipuserUpdate($data['user_id']);
        //分享奖励
        // $res1 = $rewardM->shareReward($data['user_id'],$data['amount'],$data['cny_amount'],$data['rate']);
        // if($res){
        //     $CrontabM->commit();
        // }else{
        //     $CrontabM->rollback();
        // }
    }

    public function allUpdate(){
        $memberM = new MemberAccountModel;
        $list = $memberM->field('id,level,vip_level')->select();
        // dd($list);
        $rewardM = new \addons\member\utils\Reward;
        $level_data = (new \addons\member\model\LevelConfig)->order('level desc')->select();
        $vip_data = (new \addons\member\model\VipLevel)->order('level desc')->select();
        foreach ($list as $key => $v) {
            $rewardM->updateUserLevel($v['id'],$level_data);
            $rewardM->updateVipUserLevel($v['id'],$vip_data);
        }
    }

    /**
     * 购买equip
     */
    private function unitedCreateBuy($data,$CrontabM,$rewardM){
        echo "unitedCreateBuy {$data['id']} \n";
        $status = $CrontabM->where('id',$data['id'])->value('status');
        if($status==1) return true;
        $update_data['status'] = 1;
        $update_data['update_time'] = NOW_DATETIME;
        $CrontabM->startTrans();
        $res = $CrontabM->where('id',$data['id'])->update($update_data);
        //计算用户等级
        // $rewardM->userUpdate($data['user_id']);
        // //分享奖励
        // $res1 = $rewardM->shareReward($data['user_id'],$data['amount'],$data['cny_amount'],$data['rate']);
        // if($res&&$res1){
        //     $CrontabM->commit();
        // }else{
        //     $CrontabM->rollback();
        // }
    }


    public function costAmount(){
        return;
        $BalanceM = new \addons\member\model\Balance();
        $recordM = new \addons\member\model\TradingRecord();
        $page = 0;
        $index = 0;
        $rows = 100;
        $field = 'user_id,amount';
        $map['type'] = 20;
        $map['update_time'] = ['>','2020-11-12 12:00:00'];
        $list = $recordM->field($field)->where($map)->limit($page*$rows,$rows)->select(); 
        // dd($list);
        while ($list) {
            foreach ($list as $k => $v) {
                $BalanceM->startTrans();
                $res = $this->addAmount($v['user_id'],$v['amount'],14,1,'系统回收',$BalanceM,$recordM,0,0);
                if(!$res){
                    $BalanceM->rollback();
                    continue;
                }
                $BalanceM->commit();
                //发放动态奖励
            }
            $page++;
            // $index++;
            echo "page:{$page}|index:{$index} \n";
            $list = $recordM->field($field)->where($map)->limit($page*$rows,$rows)->select(); 
        }
        echo "done \n";
    }


//    转移用户数据
//    public function uuuuuuuuu(){
//
//        $userM = new \addons\member\model\UserModel();
//        $accountM = new \addons\member\model\UserAAAAAAModel();
//        $configM = new \addons\config\model\BalanceConf();
//        $balanceM = new \addons\member\model\BalanceAAAAAAModel();
//        $type_list = $configM->getDataList(-1, -1, '', 'id', 'id asc');
//        //用户ID
//        $xxx_id = 500000;
//        //用户资产ID
//        $xxx_balance_id = 5000000;
//
//        for($i = 1; $i<400 ; $i++){
//            $user_list = $userM->getDataList($i, 1000, ' 1=1 ','*',  $order = 'id asc');
//            foreach ($user_list as $value){
//                $xxx_id += 1;
//                echo $value['id'];echo '--';
//                $data['id'] = $xxx_id;
//                $data['phone'] = $value['mobile'];
//                $data['username'] = $value['mobile'];
//                $data['password'] = md5('a123456');
//                $data['pay_password'] = md5('123456');
//                $data['card_no'] = $value['cardno'];
//                $data['is_auth'] = $value['real_name_type'];
//                $data['logic_delete'] = $value['isdel'];
//                $data['is_frozen'] = $value['isfreeze'];
//                $data['invite_code'] = $value['invitation_code'];
//                $data['pid_invite_code'] = $value['first_leve_linvitation_code'];
//                $data['register_time'] = $value['regtime'];
//                $data['real_name'] = $value['real_name'];
//                $data['pid_path'] = ',,';
//                $data['email'] = $value['email'];
//                $user_id = $accountM->add($data);
//
//                foreach ($type_list as $k => $type) {
//                    $xxx_balance_id += 1;
//                    $_balance['id'] = $xxx_balance_id;
//                    $_balance['user_id'] = $user_id;
//                    $_balance['type'] = $type['id'];
//                    $_balance['update_time'] = NOW_DATETIME;
//                    $balanceM->add($_balance);
//                }
//            }
//        }
//        echo 'ok';
//    }


////    转移用户数据
//    public function uuuuuuuuu(){
//
//        $accountM = new \addons\member\model\UserAAAAAAModel();
//        for($i = 1; $i<400 ; $i++){
//            $user_list = $accountM->getDataList($i, 1000, ' id!=500001 ','*',  $order = 'id asc');
//            foreach ($user_list as $value){
//                echo $value['id'];echo '--';
//                $data['pid'] = $accountM->where(['invite_code' => $value['pid_invite_code']])->value('id')??0;
//                $data['update_time'] = date('Y-m-d H:i:s');
//
//                $accountM->where(['id' => $value['id']])->update($data);
//            }
//        }
//        echo 'ok';
//    }

//    public function oooooo(){
//        $accountM = new \addons\member\model\UserAAAAAAModel();
////        $user_list = $accountM->order('id desc')->select();
//
//        for($i = 1; $i<400 ; $i++) {
//            $user_list = $accountM->getDataList($i, 1000, ' 1=1 ', '*', $order = 'id desc');
//            foreach ($user_list as $value) {
//                $pid_path = $accountM->getPidPath($value['id']);
//                if ($value['pid'] > 0) {
//                    echo $value['id']; echo '--';
//                    $re = $accountM->where(['id' => $value['id']])->update(['pid_path' => $pid_path, 'update_time' => date("Y-m-d H:i:s")]);
//                }
//            }
//        }
//        echo 'ok';
//    }


//    转移用户数据
    public function uuuuuuuuu(){

//        $accountAAAAAAM = new \addons\member\model\UserAAAAAAModel();
//        $accountM = new \addons\member\model\MemberAccountModel();
//        for($i = 1; $i<400 ; $i++){
//            $user_list = $accountAAAAAAM->getDataList($i, 1000, ' 1=1 ','*',  $order = 'id asc');
//            foreach ($user_list as $value){
//                echo $value['id'];echo '--';
//                $accountM->add($value);
//            }
//        }
//        echo 'ok';

//        $balanceAAAAAAM = new \addons\member\model\BalanceAAAAAAModel();
//        $balanceM = new \addons\member\model\Balance();
//
//        for($i = 1; $i<3000 ; $i++){
//            $user_list = $balanceAAAAAAM->getDataList($i, 1000, ' id>5399000 ','*',  $order = 'id asc');
//            foreach ($user_list as $value){
//                echo $value['id'];echo '--';
//                $balanceM->add($value);
//            }
//        }
//        echo 'ok';

    }

}